package day06;

public class PolyDemo {
    public static void main(String[] args) {
        Animal dog = new Dog("旺财","家狗",100.0d);

        Animal cat = new Cat("咪咪","贵宾",100.0d);

        System.out.println(dog instanceof Dog);
        System.out.println(dog instanceof Animal);
        System.out.println(dog instanceof Cat);

        dog.spark();

        cat.spark();

        System.out.println("====华丽丽的分割线=====");
        Dog d = (Dog) dog;
        d.watchForDoor();
        System.out.println("=====");
        Animal[] animals = new Animal[2];
        animals[0] = dog;
        animals[1] = cat;
        for(Animal animal : animals){
            animal.spark();
            if(animal instanceof Dog){
                Dog dg = (Dog) animal;
                dg.watchForDoor();
            }
            if(animal instanceof Cat){
                Cat c = (Cat) animal;
                c.catchMouse();
            }
        }
    }
}
